package org.bees.cms.core.util.validation;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import org.bees.cms.core.util.EntityListener;

public class Validator implements EntityListener<Validatable> {

	@PrePersist
	@Override
	public void $insert(Validatable validatable) throws Exception {
		if (!validatable.validate()) {
			throw new RuntimeException("校验失败,请确认数据的完整性!");
		}
	}

	@Override
	public void _insert(Validatable validatable) throws Exception {
		// TODO Auto-generated method stub

	}

	@PreUpdate
	@Override
	public void $update(Validatable validatable) throws Exception {
		if (!validatable.validate()) {
			throw new RuntimeException("校验失败,请确认数据的完整性!");
		}
	}

	@Override
	public void _update(Validatable validatable) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void $remove(Validatable validatable) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void _remove(Validatable validatable) throws Exception {
		// TODO Auto-generated method stub

	}

}
